<%@page import="java.text.DateFormat"%>
<%@page import="model.environment.*"%>
<%@page import="model.*" %>
<%@page import="java.util.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<% 	PageViewInfo pvi = new PageViewInfo();
	pvi.setPageTitle("Administration - item statistics");
	
	// Sending a 403 if the user isn't an admin.
	/*if (!Login.isAdministrator(session)) {
		response.sendError(403);
	}*/
	
	int itemID;
	Item item;
	
	try {
		itemID = Integer.parseInt(request.getParameter("itemID"));
		item = Items.getItem(itemID);
		
		if (item == null)
			itemID = -1;
		else
			pvi.setPageTitle("Administration - statistics for item \"" + item.getItemName() + "\"");
	} catch (NumberFormatException e) {
		itemID = -1;
	}

	DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH);
	%>
<%@include file="../parts/header.jsp" %>
	<div class="content">
		<h4>Viewing stats for: <%=Items.getItem(itemID).getItemName()%></h4>
		<%
			List<Sale> itemSales = Sales.getItemSales(itemID);
			int pieces = 0;
			int dollars = 0;
			
			for (Sale s : itemSales) {%>
		
			<div style="width:700px;border-top:1px solid black;float:left;" class="container">
				<div style="width:170px;border-right:1px dashed black;float:left;" class="coll">
					<h3 style="text-align:left;vertical-align:middle;height:80px"><a href='<%= request.getContextPath() %>/admin/showCustomerSales.jsp?customerID=<%= s.getCustomerID() %>'><%= Customers.getCustomer(s.getCustomerID()).getCustomerName() %></a> </h3>
				</div>
				<div style="width:109px;border-right:1px dashed black;float:left;" class="coll">
					<h3 style="text-align:center;vertical-align:middle;height:80px"><%= s.getSaleAmount() %> pcs.</h3>
				</div>
				<div style="width:139px;border-right:1px dashed black;float:left;" class="coll">
					<h3 style="text-align:center;vertical-align:middle;height:80px">$<%= s.getSaleItemPrice() %> per pc.</h3>
				</div>
				<div style="width:139px;border-right:1px dashed black;float:left;" class="coll">
					<h3 style="text-align:center;vertical-align:middle;height:80px">$<%= s.getSaleItemPrice() * s.getSaleAmount() %></h3>
				</div>
				<div style="width:139px;float:left;" class="coll">
					<h3 style="text-align:center;vertical-align:middle;height:80px"><%= df.format(new Date(s.getSaleTime())) %></h3>
				</div>
				<% 	pieces += s.getSaleAmount();
					dollars += s.getSaleItemPrice() * s.getSaleAmount();%>
			</div>
			<%}%>
			<br CLEAR="ALL">
				<h4>There have been sold <%=pieces%> <%=Items.getItem(itemID).getItemName()%> for a total of $<%=dollars %>.</h4>
 	</div>
<%@include file="../parts/footer.jsp" %>